package io.renren.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import io.renren.utils.DateUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.entity.SocialSecurityTransactionEntity;
import io.renren.service.SocialSecurityTransactionService;
import io.renren.utils.PageUtils;
import io.renren.utils.Query;
import io.renren.utils.R;


/**
 * 社保异动表
 * 
 * @author zhangheng
 * @email zh_123shmily@163.com
 * @date 2017-07-05 21:13:08
 */
@RestController
@RequestMapping("socialsecuritytransaction")
public class SocialSecurityTransactionController extends AbstractController{
	@Autowired
	private SocialSecurityTransactionService socialSecurityTransactionService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("socialsecuritytransaction:list")
	public R list(@RequestParam Map<String, Object> params) throws Exception {
		String[] arraycon = params.get("confirmStatus")==null?null:params.get("confirmStatus").toString().split(",");
		String[] arraypro = params.get("processStatus")==null?null:params.get("processStatus").toString().split(",");
		params.put("confirms",arraycon);
		params.put("processs",arraypro);
		//查询列表数据
        Query query = new Query(params);
		List<Map<String, Object>> socialSecurityTransactionList = socialSecurityTransactionService.queryList(query);
		int total = socialSecurityTransactionService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(socialSecurityTransactionList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}

	@RequestMapping("/updateStatus")
	@RequiresPermissions("socialsecuritytransaction:update")
	public R updateStatus(@RequestBody JSONObject jsonObject){
		//String username = getUser();
		jsonObject.put("user",getUser());
		socialSecurityTransactionService.updateStatus(jsonObject);
		return R.ok();
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("socialsecuritytransaction:info")
	public R info(@PathVariable("id") Integer id){
		SocialSecurityTransactionEntity socialSecurityTransaction = socialSecurityTransactionService.queryObject(id);
		
		return R.ok().put("socialSecurityTransaction", socialSecurityTransaction);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("socialsecuritytransaction:save")
	public R save(@RequestBody SocialSecurityTransactionEntity socialSecurityTransaction){
		socialSecurityTransactionService.save(socialSecurityTransaction);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("socialsecuritytransaction:update")
	public R update(@RequestBody SocialSecurityTransactionEntity socialSecurityTransaction){
		socialSecurityTransactionService.update(socialSecurityTransaction);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("socialsecuritytransaction:delete")
	public R delete(@RequestBody Integer[] ids){
		socialSecurityTransactionService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
